﻿//身份证正则表达式(15位)
isIDCard1=/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;
//身份证正则表达式(18位)
isIDCard2=/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/; 
//地区、性别和身份证进行判断的正则表达式：
var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"}

function cidInfo(sIdCard,gender,birthday)
{
    var sId = "";
    var iSum=0;
    var info="";
    var ErrorMsg = "身份证不正确.";
    if(!/^\d{17}(\d|x)$/i.test(sIdCard.val()))
    {
        alert(ErrorMsg);
        return false;
    }
    sId=sIdCard.val().replace(/x$/i,"a");
    if(aCity[parseInt(sId.substr(0,2))]==null)
    {
        ErrorMsg += "错误:非法地区";
        alert(ErrorMsg);
        return false;
     }
     sBirthday = sId.substr(6, 4) + "-" + sId.substr(10, 2); //+"-"+Number(sId.substr(12,2));
    //var d=new Date(sBirthday.replace(/-/g,"/"));
//    if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1))// + "-" + d.getDate())
//    {
//        ErrorMsg += "错误:非法生日";
//        alert(ErrorMsg);
//        return false;
//    }
    for(var i = 17;i>=0;i --) iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11)
    if(iSum%11!=1)
    {
        sIdCard.attr("class","error");
        ErrorMsg += "错误:非法证号";
        alert(ErrorMsg);
        return false;
    }
    
    //var BirthdayCHS = d.getFullYear()+"-"+ (d.getMonth()+1) ;//+ "-" + d.getDate()+"日"
//alert(sBirthday);
//alert(birthday.val());
    if(sBirthday != birthday.val())
    {
        ErrorMsg += "错误:出生日期与信息不符";
        alert(ErrorMsg);
        birthday.attr("class","error");
        return false;
    }
    var sgender = sId.substr(16,1)%2?"M":"F";
    if(gender.val() != sgender)
    {
        gender.attr("class","error");
        ErrorMsg += "错误:性别与填写信息不符";
        alert(ErrorMsg);
        return false;
    }
    return true;
}

function NotNull(objname)
{
    var obj =  objname;
    var value = obj.val();
    if(value=="-1"||value.length==0)
    {
        alert("申报信息不能为空.");
        obj.focus();
        obj.attr("class","error");
        return false;
    }
    return true;
}
function CheckInt(objname)
{
        var reg = /^\d+$/;//不可为空  ；/^[-+]?d*$/ 可为空         var obj =  objname;        var value = obj.val();
        if(!reg.test(value) )
        {
            alert("必须填写数字.");
            obj.focus();
            obj.attr("class","error");
            return false;
        }
		return true;
}

function validateForm()
{
    var ApplyStyle = $("#drpApplyStyle");
    var Mobile = $("#txtMobile");
    var Education = $("#drpEducation");
    var drpGender = $("#drpGender");
    var ApplyName = $("#txtApplyName");
    var ApplyTyle = $("#drpApplyStatus");
    var Birthday = $("#hiddentxtBirthday");
    var ApplyImgs =$("#ApplyImgs");
    var IDCard = $("#txtIDCard");
    var ApplyJobRank = $("#drpApplyJobRank");
    var CurrentJobRank = $("#drpCurrentJobRank");
    var GraduationTime = $("#txtGraduationTime");
    
    var GraduationSchool = $("#txtGraduationSchool");
    var GetJobRankTime = $("#txtGetJobRankTime");
    var txtConversionDate = $("#txtConversionDate");
    var EmploymentLife = $("#txtEmploymentLife");
    var ApplySubject=$("#drpSubject");
    var drpLanguage = $("#drpLanguage");
    var ApplySpeciality  = $("#drpSpeciality");
    var SpecialityName = $("#txtSpecialityName");
    var SpecialitapproveUnit = $("#txtSpecialitapproveUnit");
    var AwardsName = $("#txtAwardsName");
    var AwardsDateTime = $("#txtAwardsDateTime");
    var drpGovern = $("#drpGovern");
    var drpUnit = $("#drpUnit");
    var drpLanguageLevel = $("#drpLanguageLevel");
    var drpComputerLevel = $("#drpComputerLevel");
    var drpRegularJob = $("#drpRegularJob");
    var txtjobResult = $("#txtjobResult");
    var txtPoliticalResult = $("#txtPoliticalResult");
    var txtPaperTitle1 = $("#txtPaperTitle1");
    var txtJournalsNo1 = $("#txtJournalsNo1");
    var txtPeriodicalNo1 = $("#txtPeriodicalNo1");
    var txtPaperTitle2 = $("#txtPaperTitle2");
    var txtJournalsNo2 = $("#txtJournalsNo2");
    var txtPeriodicalNo2 = $("#txtPeriodicalNo2");
    var txtShowAddress = $("#txtShowAddress");
    
    if(NotNull(ApplyStyle)&&NotNull(drpGovern)&&NotNull(drpUnit)&&NotNull(ApplyName)&&NotNull(drpGender)
        &&NotNull(IDCard)&&NotNull(Mobile)&&NotNull(Education)&&NotNull(GraduationSchool)&&NotNull(GraduationTime)//&&NotNull(txtConversionDate)
        &&NotNull(CurrentJobRank)&&NotNull(GetJobRankTime)&&NotNull(ApplyJobRank)&&NotNull(EmploymentLife)&&NotNull(ApplyTyle)
        &&NotNull(drpLanguage)&&NotNull(drpLanguageLevel)&&NotNull(ApplySubject)&&NotNull(ApplySpeciality)&&NotNull(drpComputerLevel)
        &&NotNull(drpRegularJob)&&NotNull(txtjobResult)&&NotNull(txtPoliticalResult)
        &&NotNull(txtPaperTitle1)&&NotNull(txtJournalsNo1)//&&NotNull(txtPeriodicalNo1)
        &&NotNull(txtPaperTitle2)&&NotNull(txtJournalsNo2)//&&NotNull(txtPeriodicalNo2)
        &&NotNull(txtShowAddress)
    ) {
        if (CheckInt(EmploymentLife) && CheckInt(txtjobResult) && CheckInt(txtPoliticalResult) && validateJobRankTime(GetJobRankTime, EmploymentLife))//&&CheckInt(txtPeriodicalNo1)&&CheckInt(txtPeriodicalNo2)
        {
            if(cidInfo(IDCard,$("#drpGender"),Birthday))
            {
                var Applyplight = $("#drpApplyplight").val();
                if(Applyplight =="A") 
                {
                    return NotNull($("#txtLastApplyTime"));
                }
                else
                    return true;
            }
            else
                return false;
        }
        else
        {
            return false;
         }
    }
    else
    {
        return false;
    }
     
     return true;
 }

 function validateJobRankTime(JobRankTime, EmploymentLife) {
     var ApplyPeriod = $("#hidApplyPeriod");
     var jobRankTimeYear = "";
     if (JobRankTime.val().length > 0) {
         jobRankTimeYear = JobRankTime.val().substr(0, 4);
     }

     if (ApplyPeriod.val() - jobRankTimeYear < EmploymentLife.val()) {
         alert("聘用年限不正确");
         EmploymentLife.focus();
         EmploymentLife.attr("class", "error");
         return false;
     }
     return true;
 }

